-
Notifications
You must be signed in to change notification settings - Fork 426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve intersecting constant array with general array #1429
Improve intersecting constant array with general array #1429
Conversation
@@ -683,6 +684,13 @@ public static function intersect(Type ...$types): Type | |||
return 1; | |||
} | |||
|
|||
if ($a instanceof ConstantArrayType && !$b instanceof ConstantArrayType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment above the sort callback might need adjustments
4cf40e2
to
f93c4da
Compare
The first failure in question is about this PHPDoc:
PHPStan says about it:
I don't see why - there's no |
The second failure:
It's about this piece of code:
And the value assigned into the property:
I'm not sure who's wrong here - whether the type inference near the Link to the file in question: https://github.com/sebastianbergmann/phpunit/blob/9.5.12/src/Util/Annotation/DocBlock.php |
I think that is mostly due to differences in how Psalm and PHPStan interpret these array shape intersections. Notably, I believe in the context of how PHPStan handles it this PR is consistent, but it might make moving to (or at least borrowing ideas from) Psalm's model harder in the future. |
The root issue about these types is that "array shape" from PHPDoc and a "literal array in code" should be two different Type implementations. There are certain differences about them and right now ConstantArrayType tries to be both of them and is bad at it. Some examples:
Of course introducing new type implementation isn't trivial because we have to think and implement all the interactions with all the other types... |
Anyway, this PR is fine, thank you :) |
No description provided.